package meijuli.com.join51.business;

import android.os.Environment;

import meijuli.com.join51.business.app.MApplication;

import java.io.File;

/**
 * Some constants
 */
public class MeiJuLi {
    public static class Key {
        public static final String PATH_UPDATE_FILE = rootPath() + "/apk";
        private static String rootPath() {
            if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
                File externalCacheDir = MApplication.get().getExternalCacheDir();
                if (null != externalCacheDir) {
                    return externalCacheDir.getAbsolutePath();
                } else {
                    // 部分手机会返回返还目录为空, 例如红米note 2 ,这个时候如果强行使用app的外部缓存目录,会出现 open-failed-ebusy-device-or-resource-busy 错误
                    // 为了避免这个问题,使用其他目录代替
                    return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + MApplication.get().getPackageName();
                }
            }
            return MApplication.get().getCacheDir().getAbsolutePath();
        }
    }
}